using Firebase;
using Firebase.Analytics;
using System.Threading.Tasks;
using UnityEngine;

public class FirebaseStat : MonoBehaviour
{
	private static FirebaseStat instance;

	protected bool firebaseInitialized;

	public static FirebaseStat Instance
	{
		get
		{
			if (instance == null)
			{
				instance = (UnityEngine.Object.FindObjectOfType(typeof(FirebaseStat)) as FirebaseStat);
			}
			return instance;
		}
	}

	private void Awake()
	{
		base.gameObject.name = GetType().Name;
		Object.DontDestroyOnLoad(base.gameObject);
	}

	private void InitFirebase()
	{
		UnityEngine.Debug.Log("Enabling data collection.");
		FirebaseAnalytics.SetAnalyticsCollectionEnabled(enabled: true);
		firebaseInitialized = true;
	}

	private void Start()
	{
		FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(delegate(Task<DependencyStatus> task)
		{
			DependencyStatus result = task.Result;
			if (result == DependencyStatus.Available)
			{
				InitFirebase();
			}
			else
			{
				UnityEngine.Debug.LogError($"Could not resolve all Firebase dependencies: {result}");
			}
		});
	}

	public void LogStartLevel(int level, int vehicle)
	{
		Parameter[] parameters = new Parameter[2]
		{
			new Parameter("level_id", level + 1),
			new Parameter("vehicle_id", vehicle + 1)
		};
		FirebaseAnalytics.LogEvent("ns_level_start", parameters);
	}

	public void LogFinishLevel(int level, int vehicle, int coins)
	{
		Parameter[] parameters = new Parameter[3]
		{
			new Parameter("level_id", level + 1),
			new Parameter("vehicle_id", vehicle + 1),
			new Parameter("coinearned", coins)
		};
		FirebaseAnalytics.LogEvent("ns_level_end", parameters);
	}

	public void LogFinishLevel(string resion, string duration)
	{
	}

	public void LogSimpleEvent(string s)
	{
		FirebaseAnalytics.LogEvent(s);
	}

	public void LogNormalEvent(string events, string key, string val)
	{
		Parameter[] parameters = new Parameter[1]
		{
			new Parameter(FirebaseAnalytics.ParameterItemId, val)
		};
		FirebaseAnalytics.LogEvent(events, parameters);
	}
}
